"""
Case Type   : 功能测试
Case Name   : 创建标准库指定encoding为utf-8，LC_COLLATE、LC_CTYPE为'en_US.UTF-8'
Create At   : 2024.04.29
Owner       : lihongji
Description :
    1、创建标准库指定encoding为utf-8，LC_COLLATE、LC_CTYPE为'en_US.UTF-8'
Expect      :
    1、创建成功
History     :
"""

import os
import unittest
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class CompatibilityTest001(unittest.TestCase):

    def setUp(self):
        self.log = Logger()
        self.common = Common()
        self.sh_primary = CommonSH('PrimaryDbUser')
        self.user_node = Node('PrimaryDbUser')
        self.constant = Constant()

    def test_dolphin(self):
        self.log.info(f'----{os.path.basename(__file__)} start----')
        text = '----step1:创建和node.yml同名且兼容b库的数据库; expect:创建成功----'
        self.log.info(text)
        sql_cmd = f"drop database if exists {self.user_node.db_name};" \
                  f"create database {self.user_node.db_name} " \
                  f"encoding ='utf-8' LC_COLLATE = 'en_US.UTF-8' \
                  LC_CTYPE ='en_US.UTF-8';"
        self.log.info(sql_cmd)
        sql_res = self.sh_primary.execut_db_sql(sql_cmd, dbname='postgres')
        self.log.info(sql_res)
        self.assertIn(self.constant.CREATE_DATABASE_SUCCESS, sql_res,
                      "执行失败" + text)

    def tearDown(self):
        self.log.info('----无须清理环境 待sql用例执行完后清理即可----')
        self.log.info(f'----{os.path.basename(__file__)} end-----')
